package com.zhu.tool_test.callback;

import com.zhu.tool_test.entity.Device;

import java.util.List;
import java.util.Optional;

/**
 * @program: tool_test
 * @description: 数据事件
 * @author: ggBall
 * @create: 2021-03-05 15:41
 **/
public abstract  class DataEventCallBack implements EventCallBack<Device> {


    /***
     *
     * @Description: 插入数据
     * @author: ggBall
     * @date 2021/3/5 15:43
     * @return: boolean 插入成功返回false
     * @since 1.0
     */
    @Override
    public abstract Optional<List<Device>> insertData(String json);

    /***
     *
     * @Description: 告警操作
     * @author: ggBall
     * @date 2021/3/5 15:52
     *
     * @return: java.util.Optional<java.lang.Object>
     * @since 1.0
     */
    @Override
    public abstract Optional<Object> alarm();

    /***
     *
     * @Description: 站点更新操作
     * @author: ggBall
     * @date 2021/3/5 15:54
     *
     * @return: java.lang.Boolean
     * @since 1.0
     */
    @Override
    public abstract Boolean updateSiteState();

    /***
     *
     * @Description 通知数据插入成功之后的动作
     * @author: ggBall
     * @date 2021/3/5 16:32
     *
     * @return: void
     * @since 1.0
     */
     public void process(String json) {
         insertData(json).ifPresent(dataList -> {
             // 告警操作
             Optional<Object> alarm = alarm();
             // 站点状态更新
             Boolean updateSite = updateSiteState();

         });
     }
}
